package com.itheima04;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;


public class Test {
    public static void main(String[] args) {
        String path = "C:\\Users\\阳光正直夏明伟15805655221\\Desktop\\测试用";
        File f = new File(path);
        ArrayList<File> dirlist = new ArrayList<>();
        ArrayList<File> file = new ArrayList<>();
        diGui(f, dirlist, file);
        HashMap<String, Integer> mp = new HashMap<>();
        for (int i = 0; i < file.size(); i++) {
            File a = file.get(i);
            String[] split = a.getPath().split("\\.");
            if (split.length > 1) {
                String key = split[split.length - 1];
                if (mp.containsKey(key)) {
                    Integer integer = mp.get(key);
                    integer++;
                    mp.put(key, integer);
                } else {
                    mp.put(key, 1);
                }
            }
        }
        mp.entrySet().forEach(s -> System.out.println(s));

    }

    public static void diGui(File f, ArrayList<File> dirlist, ArrayList<File> file) {
        if (f.isFile()) {
            file.add(f);
        }
        if (f.isDirectory()) {
            dirlist.add(f);
            File[] files = f.listFiles();
            if (files != null) {
                for (File chlid : files) {

                    diGui(chlid, dirlist, file);
                }
            }
        }
    }


}
